<template>
  <el-form :inline="true" ref="personalForm" :model="personalForm" label-width="80px">
    <el-form-item label="姓名">
      <el-input v-model="personalForm.realname" clearable />
    </el-form-item>
    <el-form-item prop="deptId" label="部门" label-width="50px">
      <el-cascader
        placeholder="点击选择部门"
        :options="deptList"
        v-model="personalForm.deptId"
        :props="deptListTreeProps"
        filterable
        clearable
        change-on-select
      />
    </el-form-item>
    <!--<el-form-item label="工种">
            <el-input v-model="personalForm.craftName"></el-input>
        </el-form-item>
        <el-form-item label="学历">
            <el-input v-model="personalForm.education"></el-input>
    </el-form-item>-->

    <!--<el-form-item label="性别">
            <el-radio-group v-model="personalForm.gender">
                <el-radio-button label="">全部</el-radio-button>
                <el-radio-button :label="1">男</el-radio-button>
                <el-radio-button :label="2">女</el-radio-button>
            </el-radio-group>
    </el-form-item>-->
    <!--<el-form-item label="手机号">
            <el-input v-model="personalForm.mobile"></el-input>
        </el-form-item>
        <el-form-item label="政治面貌">
            <el-input v-model="personalForm.politicCountenance"></el-input>
        </el-form-item>
        <el-form-item label="职称">
            <el-input v-model="personalForm.professionalTitle"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
            <el-input v-model="personalForm.identityCard"></el-input>
    </el-form-item>-->
    <slot></slot>
    <!--<el-form-item label="参加">
            <el-radio-group v-model="personalPages.join">
                <el-radio-button :label="0">全部</el-radio-button>
                <el-radio-button :label="1">参加</el-radio-button>
                <el-radio-button :label="2">未参加</el-radio-button>
            </el-radio-group>
    </el-form-item>-->
    <el-form-item>
      <el-button type="primary" @click="personalSearch(1)">查询</el-button>
      <el-button  @click="_export()" type="primary">导出</el-button>
<!--      v-show="pass == '-1'"-->
      <!--<el-button @click="export_link">导出</el-button>-->
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  name: 'personalUser',
  props: {
    pass: {
      type: String,
      default: '-1'
    },
    setPersonalLoading: Function,
    setPersonalPage: Function,
    personalSubmit: Function,
    deptList: Array,
    deptListTreeProps: Object,
    parameter: Object,
    export: String
  },
  data() {
    return {
      // educationList: [], // 学历
      // politicCountenanceList: [], // 政治面貌
      // professionalTitleList: [], // 职称
      // craftList: [], // 工种
      personalForm: {
        realname: '',
        deptId: '',
        // craftName: '',
        // education: '',
        gender: ''
        // mobile: '',
        // politicCountenance: '',
        // professionalTitle: '',
        // identityCard: ''
      }
    }
  },
  async mounted() {
    // let educationList = await this.$http({
    //   url: this.$http.adornUrl('/usercenter-admin/dict/type'),
    //   method: 'post',
    //   data: {type: 'EDUCATION'}
    // })
    // console.log(educationList)
    // this.educationList = educationList.data
    // let politicCountenanceList = await this.$http({
    //   url: this.$http.adornUrl('/usercenter-admin/dept/list'),
    //   method: 'post'
    // })
    // this.politicCountenanceList = treeDataTranslate(deptList.data.filter(item => item.parentId !== -1), 'id')
    // let professionalTitleList = await this.$http({
    //   url: this.$http.adornUrl('/usercenter-admin/dept/list'),
    //   method: 'post'
    // })
    // this.professionalTitleList = treeDataTranslate(deptList.data.filter(item => item.parentId !== -1), 'id')
    // let craftList = await this.$http({
    //   url: this.$http.adornUrl('/usercenter-admin/dept/list'),
    //   method: 'post'
    // })
    // this.craftList = treeDataTranslate(deptList.data.filter(item => item.parentId !== -1), 'id')
  },
  methods: {
    _export() {
      window.location = this.$http.downloadUrl(this.export, this.parameter)
    },
    async personalSearch(page) {
      this.setPersonalLoading(true)
      this.setPersonalPage(page)
      let personalFormValues = Object.values(this.personalForm).filter(
        x => x !== '' && x !== null
      )
      let userIds
      if (personalFormValues.length) {
        userIds = await this.$http({
          url: this.$http.adornUrl('/usercenter-admin/user/getListByQueryInfo'),
          method: 'post',
          data: this.personalForm
        })
        if (userIds.data.length) {
          userIds = userIds.data.map(x => x.userId).join(',')
        } else {
          userIds = -1
        }
      } else {
        userIds = null
      }
      this.personalSubmit(userIds)
    }
  }
}
</script>
